<?php
namespace App\Http\Controllers\Mine;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ResetPasswordController extends Controller
{

    public function index()
    {

        $all = $this->all;

        $id = $all['id'];
        $password = $all['password'];
        $confirmPassword = $all['confirmPassword'];

        if($password !== $confirmPassword){
            return $this->setReturnJson(-1,'两次输入的密码不一致!');
        }

        try{
            DB::beginTransaction();
            DB::table('users')->where('id','=',$id)->update(["password" => bcrypt($password)]);
            DB::table('users_log')->insert(['id'=>$id,'action_user'=>$this->userInfo['id']]);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            Log::error(ResetPasswordController::class,['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'修改密码失败,请联系研发处理');
        }
        return $this->setReturnJson(0,'修改密码成功');



    }

}
